import sys
from tornado.ioloop import IOLoop


def print_working_order(ioloop, og):
  if og.get_working_order():
    print('Working orders:')
    for order in og.get_working_order():
      print('  %s' % str(order))
  else:
    print('No working order')
  ioloop.add_timeout(datetime.timedelta(seconds=5), print_working_order, ioloop, og)


def main(argv):
  ioloop = IOLoop.current()
  og = OkexOrderGateway('trx_btc', Config.from_config_filename('okex_pilot01'))
  og.start(ioloop)
  ioloop.add_timeout(datetime.timedelta(seconds=5), print_working_order, ioloop, og)
  ioloop.start()
  return 0


if __name__ == '__main__':
  logging.basicConfig(level='DEBUG', format='%(levelname)s %(asctime)s %(name)s] %(message)s')
  sys.exit(main(sys.argv))
